﻿CREATE PROCEDURE [dbo].[CreateMediaDefinitionAudit] 
	@MediaDefinitionId INT,
	@UserId VARCHAR(128),
	@AuditType SMALLINT,
	@AuditDate DATETIME,
	@Details VARCHAR(MAX)
AS
BEGIN

INSERT INTO MediaDefinitionAudits (MediaDefinitionId, UserId, AuditType, AuditDate, Details)
VALUES  (@MediaDefinitionId, @UserId, @AuditType, @AuditDate, @Details)


	SELECT
	MediaDefinitionAuditId, MediaDefinitionId, UserId, AuditType, AuditDate, Details,
	d.ManCoDocID, d.IndexDefinitionID, d.QueueName,
	u.UserName, u.FirstName, u.LastName
	FROM MediaDefinitionAudits [a]
	INNER JOIN dbo.MediaDefinition [d] ON a.MediaDefinitionId = d.MediaDefID
	INNER JOIN dbo.AspNetUsers [u] ON a.UserId = u.Id
	WHERE MediaDefinitionAuditId = SCOPE_IDENTITY()

END